package com.kr.aia.powerrp.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MySQLiteHelper extends SQLiteOpenHelper {
	
	// 사용자 정보 테이블
	public static final String TABLE_USER				= "USER_INFO";
	public static final String COLUMN_USER_ID			= "_id";
	public static final String COLUMN_USER_NAME			= "USER_NAME";
	public static final String COLUMN_USER_PHONE_NO		= "USER_PHONE_NO";
	
	// 고객정보 테이블
	public static final String TABLE_CUSTOMER				= "CUSTOMER_INFO";
	public static final String COLUMN_CUSTOMER_ID			= "_id";
	public static final String COLUMN_CUSTOMER_NAME			= "CUSTOMER_NAME";
	public static final String COLUMN_CUSTOMER_RECOMMENDER	= "RECOMMENDER";
	public static final String COLUMN_CUSTOMER_RELATION		= "RELATION";
	public static final String COLUMN_CUSTOMER_PHONE_NO 	= "CUSTOMER_PHONE_NO";
	
	// Role Play 그룹정보 테이블
	public static final String TABLE_RP_GROUP				= "RP_GROUP";
	public static final String COLUMN_RP_GROUP_ID			= "GROUP_ID";
	public static final String COLUMN_RP_GROUP_FILE_NAME	= "FILE_NAME";
	public static final String COLUMN_RP_GROUP_FILE_ORDER	= "FILE_ORDER";
	
	// Closing 데이터 테이블
	public static final String TABLE_CLOSING				= "CLOSING";
	public static final String COLUMN_CLOSING_ID			= "ID";
	public static final String COLUMN_CLOSING_TITLE			= "TITLE";
	public static final String COLUMN_CLOSING_CONTENT		= "CONTENT";
	
	
	private static final String DATABASE_NAME = "POWER_RP.db";
	private static final int DATABASE_VERSION = 1;

	// Database creation sql statement
	private static final String USERINFO_CREATE = "create table if not exists  "
			+ TABLE_USER + "( " + COLUMN_USER_ID + " integer primary key autoincrement, " +
								" " + COLUMN_USER_NAME+ " TEXT," +
								" " + COLUMN_USER_PHONE_NO + " TEXT" +
								");";
	
	private static final String CUSTINFO_CREATE = "create table if not exists  "
		+ TABLE_CUSTOMER + "( " + COLUMN_CUSTOMER_ID + " integer primary key autoincrement, " +
							" " + COLUMN_CUSTOMER_NAME+ " TEXT," +
							" " + COLUMN_CUSTOMER_RECOMMENDER + " TEXT," +
							" " + COLUMN_CUSTOMER_RELATION + " TEXT," +
							" " + COLUMN_CUSTOMER_PHONE_NO + " TEXT" +
							");";
	
	private static final String RP_GROUP_CREATE = "create table if not exists  "
		+ TABLE_RP_GROUP + "( " + COLUMN_RP_GROUP_ID + " integer, " +
							" " + COLUMN_RP_GROUP_FILE_NAME+ " TEXT," +
							" " + COLUMN_RP_GROUP_FILE_ORDER + " integer" +
							");";
	
	private static final String CLOSING_CREATE = "create table if not exists  "
		+ TABLE_CLOSING + "( " + COLUMN_CLOSING_ID + " integer primary key autoincrement, " +
							" " + COLUMN_CLOSING_TITLE+ " TEXT," +
							" " + COLUMN_CLOSING_CONTENT + " TEXT" +
							");";
	

	public MySQLiteHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}
	
	public void createDatabase(SQLiteDatabase database){
		database.execSQL(USERINFO_CREATE);
		database.execSQL(CUSTINFO_CREATE);
		database.execSQL(RP_GROUP_CREATE);
		database.execSQL(CLOSING_CREATE);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		/*
		Log.w(MySQLiteHelper.class.getName(),
				"Upgrading database from version " + oldVersion + " to "
						+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS" + TABLE_COMMENTS);
		onCreate(db);
		*/
	}

}
